Package tokbox.com.opentok.util

Source Code of tokbox.com.opentok.util.TokBoxXML

package tokbox.com.opentok.util;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import tokbox.com.opentok.exception.OpenTokException;

public class TokBoxXML {

  private transient Document xml;

  public TokBoxXML(final String xmlString) throws OpenTokException{
   
    try {
      this.xml = TokBoxUtils.setupDocument(xmlString);
    } catch(IOException ioe) {
      throw new OpenTokException(ioe.toString())
    } catch(ParserConfigurationException pce) {
      throw new OpenTokException(pce.toString());
    } catch(SAXException saxe) {
      throw new OpenTokException(saxe.toString());
    }
  }


  public boolean hasElement(final String elementName, final String parentElement) {
    final Node parentNode = TokBoxUtils.parseXML(parentElement, this.xml.getElementsByTagName(parentElement));
    if(parentNode == null) {
      return false;
    }
    final Node searchNode = TokBoxUtils.parseXML(elementName, parentNode.getChildNodes());

    return null != searchNode;
  }
 
  public String getElementValue(final String elementName, final String parentElement) {
    final Node parentNode = TokBoxUtils.parseXML(parentElement, this.xml.getElementsByTagName(parentElement));
    final Node searchNode = TokBoxUtils.parseXML(elementName, parentNode.getChildNodes());

    return searchNode.getTextContent();
  }


}
TOP

Related Classes of tokbox.com.opentok.util.TokBoxXML

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.